import java.util.Stack;
//判断是否是可能的出栈序列
public class Solution2 {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        int j =0;
        Stack<Integer> stack = new Stack<>();
        for(int i =0;i<pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.empty()&&(stack.peek()==popV[j])&&j<popV.length){
                j++;
                stack.pop();
            }
        }
        return stack.empty();

    }
}
